var status = 0;

function start() {
	status = -1;
	action(1, 0, 0);
}

function action(mode, type, selection) {
	if (mode == -1) {
		cm.dispose();
	} else {
		if (mode == 0) {
			cm.sendOk("Ok, see you later");
			cm.dispose();
			return;
		}
		if (mode == 1)
			status++;
		else
			status--;
		if (status == 0) {
			cm.sendNext("Hello there #b" + cm.getChar().getName() + "#k\r\nThere is a #rspecial event#k in which #eall#n monsters drop special boxes which they have stolen from me...");
		} else if (status == 1) {
			cm.sendSimple("#b#L1#Explain me about those boxes#l\r\n#L2#I have brought you some boxes#l\r\n#L3#Goodbye...#l#k");
		} else if (status == 2) {
			if (selection == 1) {
				cm.sendOk("Well, as i said, some monsters have stolen my precious boxes\r\nI want you to bring them back to me\r\n#eI can give you 1 Master Key for either 3 silver boxes or 1 golden box#n");
				cm.dispose();
			} else if (selection == 2) {
				cm.sendSimple("#b#L1#I have brought you 3 silver boxes#l\r\n#L2#I have brought you 1 golden box#l\r\n#L3#I have brought you nothing! :D#l#k");
			} else {
				cm.sendOk("Ok, see you later");
				cm.dispose();
			}
		} else if (status == 3) {
			if (selection == 1) {
				if (cm.itemQuantity(4280001) >= 3) {
					if (cm.canHold(5490000) || (cm.itemQuantity(5490000) > 0)) {
						cm.sendOk("Wonderful! thanks for helping me out, i gave you a #bMaster Key#k\r\nCome back any time!");
						cm.gainItem(4280001, -3);
						cm.gainItem(5490000, 1);
					} else {
						cm.sendOk("Good, you brought me the materials!\r\nbut wait.. i see you don't have room in your CASH inventory!");
					}
				} else {
					cm.sendOk("Hmm, i think you are short on materials, you don't seem to have 3 silver boxes");
				}
				cm.dispose();
			} else if (selection == 2) {
				if (cm.itemQuantity(4280000) >= 1) {
					if (cm.canHold(5490000) || (cm.itemQuantity(5490000) > 0)) {
						cm.sendOk("Wonderful! thanks for helping me out, i gave you a #bMaster Key#k\r\nCome back any time!");
						cm.gainItem(4280000, -1);
						cm.gainItem(5490000, 1);
					} else {
						cm.sendOk("Good, you brought me the materials!\r\nbut wait.. i see you don't have room in your CASH inventory!");
					}
				} else {
					cm.sendOk("Hmm, i think you are short on materials, you don't seem to have 1 golden box");
				}
				cm.dispose();
			} else {
				cm.sendOk("...");
				cm.dispose();
			}
		} else {
			cm.dispose();
		}
	}
}